package com.ns.sbs.oauth.acc.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ns.core.vo.login.ServObjVO;
import com.ns.sbs.oauth.acc.entry.Acc2Server;
import com.ns.sbs.oauth.acc.mapper.Acc2ServerMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;

/**
 * Service: admin管理员
 *
 * @author lw
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class Acc2ServerServiceImpl extends ServiceImpl<Acc2ServerMapper, Acc2Server> implements IAcc2ServerService {

    private final Acc2ServerMapper mapper;

    @Override
    public List<ServObjVO> getByAccId(Long id) {
        return mapper.getByAccId(id);
    }

    @Override
    public void delByAccId(Long id) {
        if (Objects.nonNull(id)) {
            mapper.delByAccId(id);
        }
    }

    @Override
    public void delByAccIds(List<Long> ids) {
        if (!CollectionUtils.isEmpty(ids)) {
            mapper.delByAccIds(ids);
        }
    }

    @Override
    public Acc2Server getByAccAndSid(Long id, Long sid) {
        return mapper.selectByAccAndSid(id, sid);
    }

    @Override
    public int updateRole(Acc2Server acc2Server) {
        mapper.delByAccIdAndRoleId(acc2Server.getAccId(), acc2Server.getRoleId());
        return mapper.insert(acc2Server);
    }

    @Override
    public void delByAccIdAndSid(Long id, Long sid) {
        mapper.delByAccIdAndSid(id, sid);
    }
}
